package com.eop.managedBean;

import javax.faces.context.FacesContext;

import org.operamasks.faces.annotation.Action;
import org.operamasks.faces.annotation.BeforeRender;
import org.operamasks.faces.annotation.Bind;
import org.operamasks.faces.annotation.Inject;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.annotation.SaveState;
import org.operamasks.faces.component.form.impl.UICombo;
import org.operamasks.faces.user.util.Browser;

import com.base.common.provider.CommonKeySelectItemProvider;
import com.base.utils.IdUtils;
import com.eop.entity.Event;

@ManagedBean(name = "eop_addEventBean", scope = ManagedBeanScope.REQUEST)
public class AddEventBean extends BaseEventBean {
	@Inject
	private FacesContext context;
	@Bind(id = "eventRangeB", attribute = "binding")
	protected UICombo eventRangeB_binding;
	@Bind(id = "eventRangeS", attribute = "binding")
	protected UICombo eventRangeS_binding;
	@SaveState
	private String first;

	@Action(id = "eventRangeB", event = "onselect", immediate = true)
	public void changeEventRangeB() {
		first = eventRangeB_binding.getSubmittedValue().toString().trim();
		eventRangeS_items = CommonKeySelectItemProvider.getDirectCommonKey(
				first, false);
	}

	@BeforeRender
	public void beforeRender(boolean isPostback) {
		if (!isPostback) {
			id = IdUtils.getUUID();

		}
	}

	@Action(id = "save")
	public void save() {
		event = new Event();
		this.setEventProperty();
		eventService.saveEvent(event);
		Browser
				.execClientScript("javascript:closeCenterLayoutTab('addEventTab')");

	}
}
